<%--
  Created by IntelliJ IDEA.
  User: ahgiy
  Date: 2023/6/29
  Time: 10:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>药品管理页面</title>
    <script src="./js/vue.js"></script>
    <script src="./elementui/index.js"></script>
    <script src="./js/jquery-3.4.1.min.js"></script>
    <link rel="stylesheet" href="./elementui/theme-chalk/index.css">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
    <h2 align="center">药品管理</h2>
    <div id="medclist">
        <div class="tb_header" style="display: flex; align-items: center; margin-bottom: 20px">
            <el-button type="primary" icon="el-icon-circle-plus" style="margin-right: 15px;" @click="toadd()" >新增用户</el-button>
            <el-input v-model="input" placeholder="请输入药品名称、分类" style="margin-right: 15px;width: 20%"></el-input>
            <el-button type="primary" icon="el-icon-search" @click="medcpagelist()">搜索</el-button>
        </div>
            <template>
                <div>
                    <el-table
                            :data="list"
                            style="width: 100%">
                        <el-table-column
                                prop="mEDICINE_ID"
                                label="药品编号"
                                width="80">
                        </el-table-column>
                        <el-table-column
                                prop="nAME"
                                label="药品名称"
                                width="150">
                        </el-table-column>
                        <el-table-column
                                prop="cATEGORY"
                                label="药品分类"
                                width="150">
                        </el-table-column>
                        <el-table-column
                                prop="supplier_info.name"
                                label="制造商">
                        </el-table-column>
                        <el-table-column
                                prop="uNIT_PRICE"
                                label="单价"
                                width="80">
                        </el-table-column>
                        <el-table-column
                                prop="qUANTITY"
                                label="库存数量"
                                width="80">
                        </el-table-column>
                        <el-table-column
                                prop="eXPIRATION_DATE"
                                label="过期日期">
                        </el-table-column>
                        </el-table-column>
                        <el-table-column label="修改" width="60">
                            <template scope="scope">
                                <el-button type="primary" icon="el-icon-edit" circle @click.native="Upd(scope.row.aDMIN_ID)"></el-button>
                            </template>
                        </el-table-column>
                        <el-table-column label="删除" width="60"  >
                            <template scope="scope">
                                <!-- 在el-button上添加一个@click.native属性，用来触发Del()方法，并将scope.row.aDMIN_ID作为参数传递 -->
                                <el-button type="danger" icon="el-icon-delete" circle @click.native="Del(scope.row.mEDICINE_ID)" ></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-row>
                        <el-col :span="24">
                            <div style="padding-top: 20px;">
                                <el-pagination
                                        @size-change="handleSizeChange"
                                        @current-change="handleCurrentChange"
                                        :current-page="pageIndex"
                                        :page-sizes="[5, 10, 50, 100]"
                                        :page-size="pageSize"
                                        layout="total, sizes, prev, pager, next, jumper"
                                        :total="pageCount">
                                </el-pagination>
                            </div>
                        </el-col>
                    </el-row>
                </div>
            </template>
    </div>
    <%--<table id="medclist" align="center"
           cellspacing="0" cellpadding="5" border="1"
           style="width: 90%;margin-top: 15px;border: 1px solid;text-align: center">
        <thead>
            <tr>
                <th width="100px">药品编号</th>
                <th >药品名称</th>
                <th>药品分类</th>
                <th>制造商</th>
                <th>单价</th>
                <th>库存数量</th>
                <th>过期日期</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody id="medclist_tbody"></tbody>
    </table>
    <div id="pages" style="text-align: right;margin-top: 15px;margin-right: 30px"></div>--%>
</body>
<script type="module">
    var vue = new Vue({
        el: '#medclist',
        data:{
            list: [],
            input: '',
            pageIndex: 1,
            pageSize: 10,
            pageCount: 0,
            showSuccessAlert: false,
            showErrorAlert: false
        },
        methods: {
            medcpagelist() {
                console.log("正在调用方法")
                $.ajax({
                    url:'medicine_info?tag=search',
                    type: 'get',
                    data:{
                        pageIndex: this.pageIndex,
                        pageSize: this.pageSize,
                        query: this.input
                    },
                    dataType: 'json',
                    success: (res) => {
                        console.log("返回的参数是:"+res)
                        this.list = res.list;
                        this.pageCount = res.pageCount;
                    }
                })
            },
            toadd(){
                parent.vue.iframeUrl = 'medc-add.jsp';
            },
            Del(id){
                this.$confirm('您是否确认删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    $.ajax({
                        url: 'medicine_info?tag=del',
                        type: 'get',
                        dataType: 'json',
                        data: {
                            id: id
                        },
                        success: (res) => {
                            if (res == 'yes') {
                                this.$alert('删除成功', '操作提示：', {
                                    confirmButtonText: '确定',
                                });
                                this.getAdminList();
                            } else {
                                this.$alert('删除失败', '操作提示：', {
                                    confirmButtonText: '确定',
                                });
                            }
                        }
                    });

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            handleSizeChange: function (size) {
                this.pageSize = size;
                this.medcpagelist();
                console.log(this.pageSize)  //每页下拉显示数据
            },
            handleCurrentChange: function(currentPage){
                this.pageIndex = currentPage;
                console.log(this.pageIndex)  //点击第几页
                this.medcpagelist();
            },
            Upd(id){
                parent.vue.iframeUrl = 'medc-upd.jsp?id='+id;
            }
        },
        mounted() {
            this.medcpagelist();
        }
    })
</script>
</html>






















